package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-13 15:17
 */
public class Solution_0374 {
    /**
     * 猜数字大小
     * 二分
     *
     * @param n
     * @return
     */
    public long guessNumber(long n) {
        long left = 1;
        long right = n;
        while (left < right) {
          long mid = left + right>> 1;
            System.out.println(mid+"===="+left+"======="+right);
            if (guess(mid) == 0) return mid;
            else if (guess(mid) == 1) left = mid+1;
            else right = mid-1;
        }
        return left;
    }

    int guess(long num) {
        //2126753390
        // 1702766719
        if (num == 1702766719)
            return 0;
        if (num > 1702766719)
            return -1;
        return 1;
    }

    public static void main(String[] args) {
        Solution_0374 solution_0374 = new Solution_0374();
        solution_0374.guessNumber(2126753390);
        System.out.println(solution_0374.guessNumber(2126753390));
    }
}
